package bo.gustavo.scrapper.zip;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;

import org.apache.commons.io.IOUtils;

/**
 * Class that unzips the template to show the results as HTML
 * 
 * @author Gustavo Vera
 * */
public class Unzipper {

	private static final String ZIP_FILENAME = "/Results.zip";

	public static void Unzip(String path) {
		File f = null;
		try {
			InputStream is = Unzipper.class.getResourceAsStream(ZIP_FILENAME);
			f = File.createTempFile("scrapper", "temp");
			OutputStream outputStream = new FileOutputStream(f);
			IOUtils.copy(is, outputStream);
			outputStream.close();
			ZipFile zipFile = new ZipFile(f);
			zipFile.extractAll(path);
		} catch (ZipException e) {
			e.printStackTrace();
		} catch (IOException e) {
		} finally {
			f.delete();
		}
	}
}
